package com.yxkj.syh.app.huarong.activities.orders.return_goods;

import android.os.Bundle;
import android.view.View;

import androidx.lifecycle.Observer;

import com.alibaba.android.arouter.facade.annotation.Autowired;
import com.alibaba.android.arouter.facade.annotation.Route;
import com.syh.app.basic.base.BaseActivity;
import com.syh.app.basic.bean.LiveDataEvent;
import com.syh.app.basic.config.BasicConstants;
import com.yxkj.syh.app.huarong.BR;
import com.yxkj.syh.app.huarong.R;
import com.yxkj.syh.app.huarong.bean.OrderInfo;
import com.yxkj.syh.app.huarong.constants.ArouterPath;
import com.yxkj.syh.app.huarong.databinding.ActivityReturnGoodsBinding;

import org.greenrobot.eventbus.EventBus;

/**
 * 退货
 */
@Route(path = ArouterPath.RETURN_GOODS_ACTIVITY)
public class ReturnGoodsActivity extends BaseActivity<ActivityReturnGoodsBinding, ReturnGoodsVM> {

    @Autowired
    OrderInfo orderInfo;

    @Override
    protected int getContentLayout() {
        return R.layout.activity_return_goods;
    }

    @Override
    protected int getViewModelId() {
        return BR.returnGoodsVM;
    }

    @Override
    protected void initView(Bundle savedInstanceState) {
        mVDBinding.titleView.setLeftOnClickListener(v -> finish());
    }

    @Override
    protected void initData() {
        mVDBinding.setOrderInfo(orderInfo);
        mViewModel.getOrderDetail(orderInfo.getId());
    }

    @Override
    protected void initObservers() {
        super.initObservers();
        mViewModel.mldReturnGoods.observe(this, aBoolean -> {
            if (aBoolean) {
                EventBus.getDefault().post(new LiveDataEvent(BasicConstants.EVENT_SELECT_ORDER_ALL));
                setResult(RESULT_OK);
                finish();
            }
        });
    }
}
